<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title><spring:message code="create_fashion_style"/></title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
	<link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
	<link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
	<script src="${ctxStatic}/layDate/laydate.js"></script>
	<c:set value="customizationUnitCost" var="customUnit"/>
	<c:set value="orderList" var="orderImage"/>
	<script type="text/javascript">
        $(document).ready(function() {
            $("#loading").hide();
            $("select").select2();
            
        });
        /*保存方法*/
        function importExcel(t){
        	var imageName = '${imageName}';
        	if (imageName!="customizationUnitCost") {
	        	if ($("#customSel").find("option:selected").val()=="") {
					alert("请选择客户！");
					return;
				}else if($("#orderType").find("option:selected").val()==""){
					alert("请选择订单类型！");
					return;
				}else if($("#orderDate").val()==""){
					/* 日本大货 和 荷兰小样  */
					if ($("#orderType").val() == "ORDER_TYPE-TYPE_50" || $("#orderType").val() == "ORDER_TYPE-TYPE_60") {
						alert("请输入订单日期！");
						return;
					}
				}
        	}
            ShowDiv();
            if (imageName=="customizationUnitCost") {
            	//定制单耗 
            	$("form")[0].action="${ctx}/customization/unitcost/insertExcelData";
			}else{
				if ($("#orderType").val() == "ORDER_TYPE-TYPE_40") {
					//小样订单 
					$("form")[0].action="${ctx}/customization/order/importSampleExcelData?customName="+$("#customSel").find("option:selected").val()+"&orderType="+$("#orderType").val();
				}else{
					//荷兰定制和荷兰大货 
		            $("form")[0].action="${ctx}/customization/order/insertExcelData?customName="+$("#customSel").find("option:selected").val()+"&orderType="+$("#orderType").val()+"&orderDate="+$("#orderDate").val();
				}
			}
            $(t).attr("disabled",true);
            var action=$("#inputForm").attr("action");
            var form = document.getElementById('inputForm');
            var fd = new FormData(form);
            var file=$("#uploadFile");
            var venderID = $("#customSel").find("option:selected").attr("data-value");
            if($(file).val()==''){
                alertInfo("<spring:message code='importExcel_error_msg'/>");
                $(t).attr("disabled",false);
                HiddenDiv();
                return false;
            }
            fd.append("file", file);
            fd.append("venderID", venderID);
            var xhr = new XMLHttpRequest();
            if (xhr.upload) {
                // 文件上传成功或是失败
                xhr.onreadystatechange = function(e) {
                    if (xhr.readyState == 4) {
                        var result=JSON.parse(xhr.responseText);
                        if (xhr.status == 200) {
                            HiddenDiv();
                            
                            if (imageName=="customizationUnitCost") {
                            	if (result == "true") {
                                    alert('<spring:message code="this_excel_ok"/>');
                                }
                            	    window.parent.frames[0].searchListForm();
                            	 	// 返回状态
                                    closeWin();
                			}else{
                                if (result == "true") {
                                    /*  ShowDiv();
                                    $.post('${ctx}/customization/order/insertTempTable?customName='+$("#customSel").find("option:selected").val(), "", function(result) {
                                        HiddenDiv(); */
                                        if (result == "true") {
                                            alert('<spring:message code="this_excel_ok"/>');
                                        }
                                        window.parent.frames[0].searchListForm();
                                        // 返回状态
                                        closeBtn();
                                    /* }, 'json'); */
                                }
                			}
                            if (result != "true") {
                                alert('<spring:message code="this_excel_upload_fail"/>\n'+result);
                                // 返回状态
                                closeBtn();
                            }
                            xhr=null;
                        }
                    }
                };
                // 开始上传
                xhr.open("POST", action, true);
                xhr.setRequestHeader("X_FILENAME", file.name);
                xhr.send(fd);
            }

            return false;
        }
        //显示加载数据
        function ShowDiv() {
            $("#loading").show();
        }

        //隐藏加载数据
        function HiddenDiv() {
            $("#loading").hide();
        }
        
        // 关闭画面并终止导入
        function closeBtn() {
        	$.post('${ctx}/customization/order/stopTread', "", function(result) {
        		closeWin();
        	},'json');
		}
    </script>
</head>
<body>
<form id="inputForm" action="${ctx}/customization/order/insertExcelData" method="post" onsubmit="formSubmit(this.action)" enctype="multipart/form-data">
<div class="tabBoxSm">
     <div class="tabSm smOrderBox" style="width:500px">
        <div class="items clearfix">
            <div class="col-50 clearfix">
                    <!-- 样板文件上传画面 -->
                     <strong style="font-size:15px;"><spring:message code="uploadExcelFile"/></strong>
            </div>
            <div class="col-50 clearfix" >
            <div style="float:right;">
               <!-- 关闭 -->
               <button type="button" class="btn-js" onclick="closeBtn();"><spring:message code="btn_cancle"/></button>
               </div>
            </div>
            <br><hr></hr>
        </div>
        <c:if test="${imageName != 'customizationUnitCost' }">
        <div class="tabSm" style="width:460px">
	        <div class="items clearfix col-50">
		        <p class="tit" style="width: 40px;">客户</p>
		        <select id="customSel" name="customName" style="width: 150px;">
			        <option value="">请选择</option>
			        <c:forEach items="${customList }" var="custom">
			        	<option value="${custom.ognizationSimpleName }" data-value="${custom.id }">${custom.ognizationName }</option>
			        </c:forEach>
		        </select>
	        </div>
	        <div class="items clearfix col-50">
	        <c:set value="ORDER_TYPE" var="orderType"/>
		        <p class="tit" style="width: 60px;">订单类型</p>
		        <select id="orderType" style="width: 100px;">
		        	<option value="">请选择</option>
		        	<c:forEach items="${fns:getDictList(orderType) }" var="item">
		        		<c:if test="${item.itemValue != 'TYPE_20'}">
		        			<option value="${item.itemCode }-${item.itemValue }">${item.itemNameCn }</option>
		        		</c:if>
		        	</c:forEach>
		        </select>
	        </div>
	    </div>
	    <div class="tabSm" style="width:460px">
	        <div class="items clearfix">
		        <p class="tit" style="width: 40px;">日期</p>
		        <input type="text" id="orderDate" onblur="CheckDate(this);" value="${fns:getDate('yyyy-MM-dd')}">
		        <label style="color: red;">&ensp;(注：该日期仅限 日本大货 使用)</label>
	        </div>
	    </div>
	        <p class="tit" style="width: 60px;padding: 5px 0;">订单文件</p>
        </c:if>
        <div class="items clearfix">
            <img id = "img" />
           <input type="file" name="file" style="width: 350px" data-rule-required="true" data-msg-required="<spring:message code="please_select_excel_file"/>">
           <button type="button" class="btn-js" onclick="importExcel(this)" style="height:34px"><spring:message code="pecimenProduct_btn_submit"/></button>
        </div>
         <div id="fileName">
         </div>
         <div id="fileSize">
         </div>
         <div id="fileType">
         </div>
         <div class="items clearfix">
             <div id="loading">
                 <img src="${ctxStatic}/images/loading.gif" alt="" style="width: 30px;height:30px"/>
                 <strong><font color="#6600ff"><spring:message code="excel_upload_waiting"/></font></strong>
             </div>
         </div>
         <div class="items clearfix">
             <strong><font color="#FF0000"><spring:message code="warning_excel_massage"/></font></strong>
         </div>
     </div>
</div>
</form>
</body>
</html>
